<template>
  <common-page
    ref="commonPage"
    :bg-path="bgPath"
    :web-path="webPath"
    :columns="columns"
    :search-items="searchItems"
    :form-items="formItems"
    :d-table-config="dTableConfig"
  />
</template>
<script>
export default {
  data() {
    return {
      // ===== ===== ===== ===== 全局属性 ===== ===== ===== =====
      // 后台接口路径
      bgPath: 'clinic/supplier/purchase/po',
      // Web路径
      webPath: 'clinic/Supplier/Purchase/Po',
      // ===== ===== ===== ===== 页面配置 ===== ===== ===== =====
      // 搜索内容
      searchItems: [
        {
          rowIndex: 1,
          items: [
            {
              code: "code",
              name: "编码",
              span: 6,
              type: "text",
              config: {
                edit: false
              }
            },
            {
              code: "minOrdTime",
              name: "最早单据时间",
              type: "datetime",
              span: 6,
              config: {
                edit: false
              }
            },
            {
              code: "maxOrdTime",
              name: "最晚单据时间",
              type: "datetime",
              span: 6,
              config: {
                edit: false
              }
            },
            {
              code: "minBusinessTime",
              name: "最早业务时间",
              type: "datetime",
              span: 6,
              config: {
                edit: false
              }
            },
            {
              code: "maxBusinessTime",
              name: "最晚业务时间",
              type: "datetime",
              span: 6,
              config: {
                edit: false
              }
            },
            {
              code: "storeCode",
              name: "门店编码",
              type: "text",
              span: 6,
              config: {
                edit: false
              }
            },
            {
              code: "storeName",
              name: "门店名称",
              type: "text",
              span: 6,
              config: {
                edit: false
              }
            },
            {
              code: "supplierCode",
              name: "供应商家编码",
              type: "text",
              span: 6,
              config: {
                edit: false
              }
            },
            {
              code: "supplierName",
              name: "供应商家名称",
              type: "text",
              span: 6,
              config: {
                edit: false
              }
            },
            {
              code: "positionCode",
              name: "药库编码",
              type: "text",
              span: 6,
              config: {
                edit: false
              }
            },
            {
              code: "positionName",
              name: "药库名称",
              type: "text",
              span: 6,
              config: {
                edit: false
              }
            },
            {
              code: "executeSign",
              name: "执行标识",
              type: "select",
              span: 6,
              config: {
                edit: false,
                keyField: "key",
                valueField: "value",
                options: [
                  {
                    key: "1",
                    value: "草稿"
                  },
                  {
                    key: "2",
                    value: "完成"
                  }
                ]
              }
            },
            {
              code: "sourceCode",
              name: "来源单号",
              type: "text",
              span: 6,
              config: {
                edit: false
              }
            }
          ]
        }
      ],
      // 列表内容
      columns: [
        {
          code: "code",
          name: "编码",
          span: 6,
          type: "text",
          config: {
            edit: false
          }
        },
        {
          code: "ordTime",
          name: "单据时间",
          type: "datetime",
          span: 6,
          config: {
            edit: false
          }
        },
        {
          code: "businessTime",
          name: "业务时间",
          type: "datetime",
          span: 6,
          config: {
            edit: false
          }
        },
        {
          code: "storeCode",
          name: "门店编码",
          type: "text",
          span: 6,
          config: {
            edit: false
          }
        },
        {
          code: "storeName",
          name: "门店名称",
          type: "text",
          span: 6,
          config: {
            edit: false
          }
        },
        {
          code: "supplierCode",
          name: "供应商家编码",
          type: "text",
          span: 6,
          config: {
            edit: false
          }
        },
        {
          code: "supplierName",
          name: "供应商家名称",
          type: "text",
          span: 6,
          config: {
            edit: false
          }
        },
        {
          code: "positionCode",
          name: "药库编码",
          type: "text",
          span: 6,
          config: {
            edit: false
          }
        },
        {
          code: "positionName",
          name: "药库名称",
          type: "text",
          span: 6,
          config: {
            edit: false
          }
        },
        {
          code: "executeSign",
          name: "执行标识",
          type: "select",
          span: 6,
          config: {
            edit: false,
            keyField: "key",
            valueField: "value",
            options: [{
              key: "1", value: "草稿"
            }, {
              key: "2", value: "完成"
            }]
          }
        },
        {
          code: "sourceCode",
          name: "来源单号",
          type: "text",
          span: 6,
          config: {
            edit: false
          }
        },
        {
          code: "positionPositionSign",
          name: "位置标识",
          type: "select",
          span: 6,
          config: {
            edit: false,
            keyField: "key",
            valueField: "value",
            options: [{
              key: "1", value: "药房"
            }, {
              key: "2", value: "药库"
            }, {
              key: "3", value: "仓库"
            }]
          }
        },
        {
          code: "positionClassifySign",
          name: "分类标识",
          type: "select",
          span: 6,
          config: {
            edit: false,
            keyField: "key",
            valueField: "value",
            options: [{
              key: "1", value: "中成药"
            }, {
              key: "3", value: "饮片"
            }, {
              key: "5", value: "产品"
            }]
          }
        }
      ],
      // 增加/修改/详情 表单
      formItems: [
        {
          rowIndex: 1,
          items: [
            {
              code: "code",
              name: "编码",
              span: 6,
              type: "text",
              config: {
                edit: false,
                require: true,
                rules: [
                  { required: true, message: '请输入编码', trigger: 'blur' }
                ]
              }
            },
            {
              code: "ordTime",
              name: "单据时间",
              type: "datetime",
              span: 6,
              config: {
                edit: false
              }
            },
            {
              code: "businessTime",
              name: "业务时间",
              type: "datetime",
              span: 6,
              config: {
                edit: false
              }
            },
            {
              code: "storeCode",
              span: 6,
              name: "门店编码",
              type: "popup",
              config: {
                url: "base/user/user/store",
                filedList: [
                  { code: 'id', name: 'ID' },
                  { code: 'code', name: '编码' },
                  { code: 'name', name: '名称' }
                ],
                searcher: {},
                defaultValue: "",
                minLength: 0,
                maxLength: 20,
                disabled: false,
                require: true,
                rules: [
                  { required: true, message: '请输选择门店', trigger: 'blur' }
                ]
              },
              handleEvent: {
                /**
                 * 开窗组件被选择
                 * @param code
                 * @param row
                 */
                onPopupClick: (code, row) => {
                  this.$refs.commonPage.updateDTableData("storeName", row.name)
                  this.$refs.commonPage.updateDTableData("storeCode", row.code)
                  this.$refs.commonPage.updateDTableData("storeId", row.id)
                }
              }
            },
            {
              code: "storeName",
              name: "门店名称",
              type: "text",
              span: 6,
              config: {
                edit: false,
                disabled: true
              }
            },
            {
              code: "supplierCode",
              span: 6,
              name: "供应商编码",
              type: "popup",
              config: {
                url: "clinic/supplier/supplier/supplier",
                filedList: [
                  { code: 'id', name: 'ID' },
                  { code: 'code', name: '编码' },
                  { code: 'name', name: '名称' }
                ],
                searcher: {},
                defaultValue: "",
                minLength: 0,
                maxLength: 20,
                disabled: false,
                require: true
              },
              handleEvent: {
                /**
                 * 开窗组件被选择
                 * @param code
                 * @param row
                 */
                onPopupClick: (code, row) => {
                  this.$refs.commonPage.updateFormData("supplierName", row.name)
                  this.$refs.commonPage.updateFormData("supplierCode", row.code)
                  this.$refs.commonPage.updateFormData("supplierId", row.id)
                }
              }
            },
            {
              code: "supplierName",
              name: "供应商家",
              type: "text",
              span: 6,
              config: {
                edit: false,
                disabled: true
              }
            },
            {
              code: "positionCode",
              span: 6,
              name: "药库编码",
              type: "popup",
              config: {
                url: "clinic/inventory/inventory/position",
                filedList: [
                  { code: 'id', name: 'ID' },
                  { code: 'code', name: '编码' },
                  { code: 'name', name: '名称' },
                  {
                    code: "positionSign", name: "位置标识", type: "select", options: [{
                      key: "1", value: "药房"
                    }, {
                      key: "2", value: "药库"
                    }, {
                      key: "3", value: "仓库"
                    }]
                  },
                  {
                    code: "classifySign", name: "分类标识", type: "select", options: [{
                      key: "1", value: "中成药"
                    }, {
                      key: "3", value: "饮片"
                    }, {
                      key: "5", value: "产品"
                    }]
                  }
                ],
                searcher: {},
                defaultValue: "",
                minLength: 0,
                maxLength: 20,
                disabled: false,
                require: true
              },
              handleEvent: {
                /**
                 * 开窗组件被选择
                 * @param code
                 * @param row
                 */
                onPopupClick: (code, row) => {
                  this.$refs.commonPage.updateFormData("positionName", row.name)
                  this.$refs.commonPage.updateFormData("positionCode", row.code)
                  this.$refs.commonPage.updateFormData("positionId", row.id)
                  this.$refs.commonPage.updateFormData("positionClassifySign", row.classifySign)
                  this.$refs.commonPage.updateFormData("positionPositionSign", row.positionSign)
                }
              }
            },
            {
              code: "positionName",
              name: "药库名称",
              type: "text",
              span: 6,
              config: {
                edit: false,
                disabled: true
              }
            },
            {
              code: "executeSign",
              name: "内容",
              type: "select",
              span: 6,
              config: {
                edit: false,
                keyField: "key",
                valueField: "value",
                options: [{
                  key: "1", value: "草稿"
                }, {
                  key: "2", value: "完成"
                }]
              }
            },
            {
              code: "sourceCode",
              name: "来源单号",
              type: "text",
              span: 6,
              config: {
                edit: false
              }
            }
          ]
        }
      ],
      // 子表配置
      dTableConfig: [
        {
          key: "poItem",
          name: "采购订单项",
          columns: [
            {
              code: "line",
              name: "行号",
              type: "number",
              config: {
                align: "center",
                precision: 2
              }
            },
            {
              code: "poCode",
              name: "单据编码",
              type: "text",
              config: {
                align: "center",
                disabled: true
              }
            },
            {
              code: "supplierMaterielCode",
              span: 6,
              name: "药品编码",
              type: "popup",
              config: {
                url: "clinic/supplier/supplier/suppliermateriel",
                filedList: [
                  { code: 'id', name: 'ID', config: { align: "center" }},
                  { code: 'code', name: '编码', config: { align: "center" }},
                  { code: 'name', name: '名称', config: { align: "center" }}
                ],
                searcher: {},
                defaultValue: "",
                minLength: 0,
                maxLength: 20,
                disabled: false,
                require: true,
                rules: [
                  { required: true, message: '请输选择门店', trigger: 'blur' }
                ]
              },
              handleEvent: {
                /**
                 * 开窗组件被选择
                 * @param line
                 * @param code
                 * @param row
                 */
                onPopupClick: (line, code, row) => {
                  this.$refs.commonPage.updateDTableData(line, "poItem", "supplierMaterielName", row.name)
                  this.$refs.commonPage.updateDTableData(line, "poItem", "supplierMaterielCode", row.code)
                  this.$refs.commonPage.updateDTableData(line, "poItem", "supplierMaterielId", row.id)
                }
              }
            },
            {
              code: "supplierMaterielName",
              name: "药品名称",
              type: "text",
              span: 6,
              config: {
                edit: false,
                disabled: true
              }
            },
            {
              code: "qualitySign",
              name: "品质标识",
              type: "text",
              span: 6,
              config: {
                edit: false,
                disabled: true,
                options: [{
                  key: "1", value: "普通"
                }, {
                  key: "2", value: "精品"
                }]
              }
            },
            {
              code: "batchCode",
              name: "批次号",
              type: "text",
              span: 6,
              config: {
                edit: false,
                disabled: true
              }
            },
            {
              code: "number",
              name: "数量",
              type: "number",
              span: 6,
              config: {
                edit: false,
                disabled: true
              }
            },
            {
              code: "costPrice",
              name: "成本单价",
              type: "number",
              span: 6,
              config: {
                edit: false,
                disabled: true,
                precision: 2
              }
            },
            {
              code: "costAmount",
              name: "成本金额",
              type: "number",
              span: 6,
              config: {
                edit: false,
                disabled: true,
                precision: 2
              }
            }
          ]
        }
      ]
    }
  }
}
</script>
